module.exports = class extends think.Model {
    payment_field(ops) {
        return {
            out_trade_no: ops.out_trade_no[0],
            transaction_id: ops.transaction_id[0],
            openid: ops.openid[0],
            trade_type: ops.trade_type[0],
            bank_type: ops.bank_type[0],
            total_fee: Number(ops.total_fee[0]) / 100,
            cash_fee: Number(ops.cash_fee[0]) / 100,
            time_end: ops.time_end[0],
            source: ops.source,
        };
    }

    IsExsit(out_trade_no) {
        return new Promise(resolve => {
            let i = 0;
            const notiy = setInterval(async() => {
                i++;
                const pay_select = await think.model('payment_flow').where({out_trade_no: out_trade_no}).find();
                if (!think.isEmpty(pay_select)) {
                    clearInterval(notiy);
                    resolve(pay_select);
                }
                if (i === 500) clearInterval(notiy);
            }, 300);
        });

    }
};
